import json
import logging

import yagmail
import yaml

# 读取yaml文件的方法
def read_yaml(file_path):
    with open(file_path,'r',encoding='utf-8') as e:
        return yaml.safe_load(e)

# 读取json文件的方法
def read_json(file_path):
    with open(file_path,'r',encoding='utf-8') as e:
        return json.load(e)


def get_logger(name='test_logger'):
    logger = logging.getLogger(name)
    if not logger.handlers:
        fmt = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        # 文件
        file_hd = logging.FileHandler('log.txt',encoding='utf-8')
        file_hd.setFormatter(fmt)
        logger.addHandler(file_hd)
        # 控制台
        kong_hd=logging.StreamHandler()
        kong_hd.setFormatter(fmt)
        logger.addHandler(kong_hd)
        # 设置日志级别
        logger.setLevel(logging.INFO)
    return logger

# 发送邮件的方法
def Emails(data):
    emails = yagmail.SMTP(user='2017681094@qq.com',password='cnvwxvgkvfhrdhcj',host='smtp.qq.com',port='465')
    emails.send(to='2017681094@qq.com',subject='测试报告',contents='测试报告',attachments=data)
    emails.close()